<?php
$this->load->view('header');

if (strlen($this->session->flashdata('Error')) > 0) {
    echo '<div class="alert alert-danger alert-dismissable">';
    echo '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' . $this->session->flashdata('Error') . '</div>';
    $this->session->unset_userdata('Error');
} elseif (strlen($this->session->flashdata('Success')) > 0) {
    echo '<div class="alert alert-success alert-dismissable">';
    echo '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' . $this->session->flashdata('Success') . '</div>';
    $this->session->unset_userdata('Success');
}
?>

<script type="text/javascript">
    function search_data() {
        $.post("<?= site_url() ?>setup/search_borrow", {
            search_by_name: $('#search_by_name').val(),
			search_by_status: $('#search_by_status').val()
            // date1: $('#date1').val(),
			// date2: $('#date2').val()
        },
        function(data) {
            $('#tablecontent').html(data);
        });
    }

/*    function view_detail(room_id,type){
		$.post("<?= site_url() ?>setup/view_detail_item", {room_id: room_id, type: type}, function(data) {
            $('#loader').html(data);
        });
	}
	
	function add_data() {
        $.post("<?= site_url() ?>setup/add_warehouse_item_view", function(data) {
            $('#loader').html(data);
        });
    }
	
	function edit_data(room_id) {		
        $.post("<?= site_url() ?>setup/edit_warehouse_item_view", {room_id: room_id}, function(data) {
            $('#loader').html(data);
        });
    }
	
	function delete_data(room_id){		
		$.post("<?= site_url() ?>setup/delete_warehouse_item", {room_id: room_id}, function(data) {
            $('#loader').html(data);
        });
	}
*/	
	function view_warehouse() {
        $.post("<?= site_url() ?>setup/ga_warehouse", function(data) {
            // $('#loader').html(data);
			window.location = '<?php echo base_url();?>setup/ga_warehouse';
        });
    }
	
	function load_page_borrow(page, ipp) {
        $.post("<?= site_url() ?>setup/load_page_borrow", {
            page: page,
            ipp: ipp,
            search_by_name: $('#search_by_name').val(),
			search_by_status: $('#search_by_status').val()
            // date1: $('#date1').val(),
			// date2: $('#date2').val()
        },
        function(data) {
            $('#tablecontent').html(data);
        });
    }
	
	function activation_order(roomd_id, cond) {
        var page = $('#page_val').val();
        var ipp = $('#ipp_val').val();
        var str = 'Are you sure to complete this order?';
        if(cond!='Y'){
            str = 'Are you sure to borrow this item?';
        }
        var cek = confirm(str);
        if (cek) {
            $.post("<?= site_url() ?>setup/activation_order", {
                roomd_id: roomd_id,
                cond : cond
            },
            function(data) {
                load_page_borrow(page, ipp);				
            });
        }
    }
</script>

<div id="loader" class="container">
    <form method=post id="access" action="#" enctype="multipart/form-data" class="form-horizontal" role="form">
	<div class="col-md-offset-1">
		<div class="col-md-11">
			<div class="panel panel-default">
				<div class="panel-heading">
					<h4 class="panel-title"><b class="caret"></b><b> Search Item Borrow</b></h4>
				</div>
				<div class="panel-body">
					<div class="col-md-6">
						<div class="form-group">
							<label class="col-md-4"><p class="text-left">Item Name</p></label>
							<div class="col-md-7"><input type="text" class="form-control input-sm" id="search_by_name" name="search_by_name"></div>
						</div>						
					</div>
					<div class="col-sm-6 col-md-5">
						<div class="form-group">
							<label class="col-md-4"><p class="text-left">Order Status</p></label>
							<div class="col-md-8">
								<select name="search_by_status" id="search_by_status" class="form-control input-sm">                         
									<option value="">-- select --</option>			
									<option value="Y">Borrow</option>
									<option value="N">Complete</option>
								</select>
							</div>
						</div>
						<div class="form-group">
							<div class="col-md-4"><label for="button" class="control-label">&nbsp;</label></div>
							<div class="col-md-4">
								<button type="button" class="btn btn-primary btn-block" onclick="search_data();">
								<!--span class="glyphicon glyphicon-search"></span--> Search</button>
							</div>
							<div class="col-md-4">
								<button type="reset" class="btn btn-default btn-block">
								<!--span class="glyphicon glyphicon-refresh"></span--> Clear</button>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="panel-body well">
				<div class="col-md-6">
					<div class="form-group">
						<div class="col-md-5">
							<button type="button" class="btn btn-info btn-block" onclick="view_warehouse();">
							<!--span class="glyphicon glyphicon-eye-open"></span--> View Warehouse</button>
						</div>
					</div>
				</div>
				<div id="tablecontent" class="col-md-12">						
					<div class="form-group">
						<div class="table-responsive">
							<table class="table table-bordered table-condensed table-striped" style="background:#f9f9f9;">
								<thead>
									<tr>
										<th class="tblhead" style="width:4%;text-align:center;">No</th>
										<th class="tblhead" style="width:12%;text-align:center;">Order No</th>
										<th class="tblhead" style="width:12%;text-align:center;">Item Name</th>
										<th class="tblhead" style="width:12%;text-align:center;">Item Qty</th>                        
										<th class="tblhead" style="width:12%;text-align:center;">Order Date</th>						
										<th class="tblhead" style="width:12%;text-align:center;">Order Status</th>
										<!--th class="tblhead" style="width:12%;text-align:center;">Action</th-->
									</tr>
								</thead>
								<tbody>
									<?php
									if (empty($list_data)) {
										?>
										<tr><td colspan="6" style="text-align:center">No Data Available</td></tr>
										<?php
									} else {
										foreach ($list_data as $row) {
											?>
											<tr>
												<?php
												$room_id 		 	= $row["ROOM_ID"];
												$roomd_description 	= $row["ROOMD_DESCRIPTION"];
												$roomd_qty 			= $row["ROOMD_QTY"];
												$warehouse_id		= $row["WAREHOUSE_ID"];
												$roomd_status 		= $row["ROOMD_STATUS"];
												$roomd_id 			= $row["ROOMD_ID"];
												$room_date			= $row["ROOM_DATE"];
												$item_status 		= (!empty($roomd_status) && $roomd_status == 'Y') ? 'Borrow' : 'Complete';
												?>

												<td bgcolor="#FFFFFF" class="tbl-content-c" style="text-align:center;"><?php echo $row["RECNUM"]; ?>.</td>
												<td bgcolor="#FFFFFF" class="tbl-content-c" style="text-align:left;"><?php echo $roomd_id; ?></td>
												<td bgcolor="#FFFFFF" class="tbl-content-c" style="text-align:left;"><?php echo $roomd_description; ?></td>
												<td bgcolor="#FFFFFF" class="tbl-content-c" style="text-align:left;"><?php echo $roomd_qty; ?></td>
												<td bgcolor="#FFFFFF" class="tbl-content-c" style="text-align:left;"><?php echo $room_date; ?></td>								
												<td bgcolor="#FFFFFF" class="tbl-content-c" style="text-align:center;">
													<?php if($roomd_status=='Y') :?>
														<a class="btn btn-sm btn-warning" href="#" onclick="activation_order('<?php echo $roomd_id ?>', '<?php echo $roomd_status ?>');">
														<!--span class="glyphicon glyphicon-cog"></span--> <?php echo $item_status; ?></a>
													<?php else: ?>
														<a class="btn btn-sm btn-primary" href="#" onclick="activation_order('<?php echo $roomd_id ?>', '<?php echo $roomd_status ?>');">
														<!--span class="glyphicon glyphicon-ok"></span--> <?php echo $item_status; ?></a>
													<?php endif; ?>
												</td>
												<!--td bgcolor="#FFFFFF" class="tbl-content-c" style="text-align:center;">
													<a class="btn btn-sm btn-warning" href="#" onclick="edit_data('<?php echo $room_id ?>');">
														<!--span class="glyphicon glyphicon-edit"></span> Edit</a>
													<a class="btn btn-sm btn-danger" href="#" onclick="delete_data('<?php echo $room_id ?>');">
														<!--span class="glyphicon glyphicon-delete"></span> Delete</a>
												</td-->
											</tr>
											<?php
										}
									}
									?>
								</tbody>
							</table>
						</div>
					</div>
					<div class="form-group">
						<div id="mypaging">
							<?php
							echo $paging;
							echo $jump_page;
							echo $ipp;
							?>
						</div>								
					</div>
				</div>
			</div>
		</div>
	</div>
	</form>
</div>

<?php $this->load->view('footer'); ?>

<script>
/*$('#image_button').click(function()
{
	$('#date1').datetimepicker('show'); //support hide,show and destroy command
});
$('#image_button2').click(function()
{
	$('#date2').datetimepicker('show'); 
});

$('#date1').datetimepicker({
	scrollInput:false,
	closeOnDateSelect:true,
	datepicker:true,
	timepicker:false,
	format:'d/m/Y',
	minDate:'-1970/01/01',
	onGenerate:function( ct ){$(this).find('.xdsoft_date.xdsoft_weekend').addClass('xdsoft_disabled');}
});
$('#date2').datetimepicker({
	scrollInput:false,
	closeOnDateSelect:true,
	datepicker:true,
	timepicker:false,
	format:'d/m/Y',
	minDate:'-1970/01/01',
	onGenerate:function( ct ){$(this).find('.xdsoft_date.xdsoft_weekend').addClass('xdsoft_disabled');}
});*/
</script>